package com.sky.controller.user;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.SetmealDish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author guozh
 */
@RestController("UserSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
public class SetmealController {
    @Autowired
    public SetmealService setmealService;

    /**
     * 根据分类 id查询套餐
     */
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    @GetMapping("/list")
    public Result<List<SetmealVO>> selectSetmealList(Long categoryId) {
        log.info("根据分类 id查询套餐{}", categoryId);
        List<SetmealVO> list = setmealService.selectSetmealList(categoryId);
        return Result.success(list);
    }

    /**
     * 根据套餐id查询包含的菜品
     *
     * @param id id
     * @return Result<SetmealVO>
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishById(@PathVariable Long id) {
        log.info("根据套餐id查询套餐信息:{}", id);
        List<DishItemVO> dishVOList = setmealService.getDishItemById(id);
        return Result.success(dishVOList);
    }

}
